inspector: Kepp tree iter in type data
authorBenjamin Otte <otte@redhat.com>
Mon, 13 Oct 2014 08:20:29 +0000 (10:20 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 14 Oct 2014 12:03:06 +0000 (14:03 +0200)
This way we don't have to clear/refill the model every time but can keep
the existing model and only update the values.

A nice side benefit is that running an update keeps the current selection.

gtk/inspector/statistics.c

index 4e9570c3e49694bd69b10fd72f01b1be87183858..f95479edeb903860978ee34fe9a52b84d97484ed 100644 (file)
@@ -45,6 +45,7 @@ struct _GtkInspectorStatisticsPrivate
 
 typedef struct {
   GType type;
+  GtkTreeIter treeiter;
   gint self1;
   gint cumulative1;
   gint self2;
@@ -84,6 +85,11 @@ add_type_count (GtkInspectorStatistics *sl, GType type)
     {
       data = g_new0 (TypeData, 1);
       data->type = type;
+      gtk_list_store_append (GTK_LIST_STORE (sl->priv->model), &data->treeiter);
+      gtk_list_store_set (GTK_LIST_STORE (sl->priv->model), &data->treeiter,
+                          COLUMN_TYPE, data->type,
+                          COLUMN_TYPE_NAME, g_type_name (data->type),
+                          -1);
       g_hash_table_insert (sl->priv->counts, GSIZE_TO_POINTER (type), data);
     }
 
@@ -95,6 +101,12 @@ add_type_count (GtkInspectorStatistics *sl, GType type)
   data->self2 = self;
   data->cumulative2 = cumulative;
 
+  gtk_list_store_set (GTK_LIST_STORE (sl->priv->model), &data->treeiter,
+                      COLUMN_SELF1, data->self1,
+                      COLUMN_CUMULATIVE1, data->cumulative1,
+                      COLUMN_SELF2, data->self2,
+                      COLUMN_CUMULATIVE2, data->cumulative2,
+                      -1);
   return cumulative;
 }
 
@@ -120,27 +132,7 @@ update_type_counts (GtkInspectorStatistics *sl)
 static void
 refresh_clicked (GtkWidget *button, GtkInspectorStatistics *sl)
 {
-  GHashTableIter iter;
-  TypeData *data;
-  GtkTreeIter treeiter;
-
   update_type_counts (sl);
-
-  gtk_list_store_clear (GTK_LIST_STORE (sl->priv->model));
-
-  g_hash_table_iter_init (&iter, sl->priv->counts);
-  while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&data))
-    {
-      gtk_list_store_append (GTK_LIST_STORE (sl->priv->model), &treeiter);
-      gtk_list_store_set (GTK_LIST_STORE (sl->priv->model), &treeiter,
-                          COLUMN_TYPE, data->type,
-                          COLUMN_TYPE_NAME, g_type_name (data->type),
-                          COLUMN_SELF1, data->self1,
-                          COLUMN_CUMULATIVE1, data->cumulative1,
-                          COLUMN_SELF2, data->self2,
-                          COLUMN_CUMULATIVE2, data->cumulative2,
-                          -1);
-    }
 }
 
 static gboolean